﻿using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;

namespace SampleControls {
    public class ContentSerialization : UserControl {
        private Label label1;
        private Container components = null;

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public DimensionData Dimensions {
            get {
                return new DimensionData(this);
            }
        }

        public ContentSerialization() {
            InitializeComponent();
        }

        protected override void Dispose(bool disposing) {
            if (disposing) {
                if (components != null)
                    components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent() {
            this.label1 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label1.Location = new System.Drawing.Point(3, 0);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(250, 25);
            this.label1.TabIndex = 0;
            this.label1.Text = "ContentSerializationControl";
            // 
            // ContentSerialization
            // 
            this.BackColor = System.Drawing.SystemColors.ActiveCaption;
            this.Controls.Add(this.label1);
            this.Name = "ContentSerialization";
            this.Size = new System.Drawing.Size(256, 30);
            this.ResumeLayout(false);
            this.PerformLayout();

        }
    }

    //[TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))]
    // This attribute indicates that the public properties of this object should be listed in the property grid.
    public class DimensionData {
        private Control owner;

        // This class reads and writes the Location and Size properties from the Control which it is initialized to.
        internal DimensionData(Control owner) {
            this.owner = owner;
        }

        public Point Location {
            get {
                return owner.Location;
            }
            set {
                owner.Location = value;
            }
        }

        public Size FormSize {
            get {
                return owner.Size;
            }
            set {
                owner.Size = value;
            }
        }
    }
}
